<?php

/**
 * Book
 *  
 * @author bichnkn
 * @version 
 */

class Application_Model_Book {
	protected $_id;
	protected $_title;
	protected $_author;
	protected $_posted_date;
	protected $_posted_by;
	protected $_description;
	protected $_price;
	protected $_image;
	
	public function __construct(array $arr = null){
		if(is_array($arr)){
			$this->setOptions($arr);
		}
	}
	
	public function __set($name, $value)
	{
		$method = 'set' . $name;
		if (!method_exists($this, $method)) {
			throw new Exception('Invalid book property');
		}
		$this->$method($value);
	}
	
	public function __get($name)
	{
		$method = 'get' . $name;
		if (!method_exists($this, $method)) {
			throw new Exception('Invalid book property');
		}
		return $this->$method();
	}
	
	public function setTitle($value){
		$this->_title = $value;
		return $this;
	}
	
	public function setAuthor($value){
		$this->_author = $value;
		return $this;
	}
	
	public function setId($value){
		$this->_id = $value;
		return $this;
	}
	
	public function setPosted_date($value){
		$this->_posted_date = $value;
		return $this;
	}
	
	public function setPosted_by($value){
		$this->_posted_by = $value;
		return $this;
	}
	
	public function setDescription($value){
		$this->_description = $value;
		return $this;
	}
	
	public function setPrice($value){
		$this->_price = $value;
		return $this;
	}
	
	public function setImage($value){
		$this->_image = $value;
		return $this;
	}
	
	public function getId(){
		return $this->_id;
	}
	
	public function getTitle(){
		return $this->_title;
	}
	
	public function getPosted_date(){
		return $this->_posted_date;
	}
	
	public function getPosted_by(){
		return $this->_posted_by;
	}
	
	public function getAuthor(){
		return $this->_author;
	}
	
	public function getPrice(){
		return $this->_price;
	}
	
	public function getDescription(){
		return $this->_description;
	}
	
	public function getImage(){
		return $this->_image;
	}
	
	public function setOptions(array $arr){
		$methods = get_class_methods($this);
		foreach($arr as $key => $value){
			$set = 'set'.ucfirst($key);
			if(in_array($set, $methods)){
				$this->$set($value);
			}
		}
	}
	
	public function isEmpty(){
		if($this->id === null && $this->title === null && $this->price === null && $this->description === null &&
				$this->author === null && $this->image === null && $this->posted_by === null && $this->posted_date === null){
			return true;	
		}else{
			return false;
		}
	}
}
